﻿using HelloWPF.Study.WPFControls.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HelloWPF.Study.WPFControls.ProgressBar
{
    /// <summary>
    /// ProgressBarWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ProgressBarWindow : Window
    {
        ProgressBarViewModel viewModel;
        public ProgressBarWindow()
        {
            InitializeComponent();
            viewModel = new ProgressBarViewModel();
            this.DataContext = viewModel;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //pbar2.Value = 0;
            //for (int i = 0; i < pbar2.Maximum; i++)
            //{
            //    pbar2.Value = i;
            //    lblVal.Content = pbar2.Value + "%";
            //    Thread.Sleep(100);
            //}
            int max = 100;
            Task.Run(() =>
            {
                for (int i = 0; i <= max; i++)
                {
                    pbar2.Dispatcher.Invoke(() =>
                    {
                        pbar2.Value = i;
                        //lblVal.Content = pbar2.Value + "%";
                    });
                    Thread.Sleep(100);//0.1's total = 100 * 100 = 10s
                }
            });//假设已经编译完成了，我这里还在走-太假了
        }

        private void Pbar2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            lblVal.Content = e.NewValue + "%";
        }
    }
}
